home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Games: 500 MB Amiga Software
/
500 MB Amiga Software - Euber 130 - Amiga Games Disc & Mag.iso
/
userbox
/
publicdomain
/
pointereyes
/
v1.1.source
/
pointereyesv1.1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-02
|
16KB
|
524 lines
/* PointerEyes Copyright © 1994 John Hughes. All Rights Reserved.
Coded by: John Hughes
E-Mail: johughes@heartland.bradley.edu
Compiler: SAS/C 6.51
Date: July 12,1994
Machine: A4000 68EC030 / 25 Mhz 6MB RAM
PointerEyes was written in a modular fashion, but
for the simplicity of the program, and since
there are so few variables, most of the functions
do not take parameters, and most variables are global.
However in most cases you would want to make as many
local variables as possible so that they are not
accidently altered outside of there function.
This source code may only be distributed unmodified and
accompanied by the entire PointerEyes archive.
This source code is 100% compileable with SAS/C and GCC.
And it should work with DICEC. Please see the docs.
The GCC support was added by Gunther Nikl.
*/
#include <exec/execbase.h>
#include <math.h>
#include <stdlib.h> /* abs() srand() rand() */
#include <time.h> /* time() */
#include <dos/notify.h> /* StartNotify() */
#include <exec/memory.h> /* MEMF_CLEAR */
#include <libraries/gadtools.h> /* GTMN_FrontPen */
#if defined(__SASC) || defined(LATTICE)
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/intuition.h>
#else
#if defined(__GNUC__) && defined(__OPTIMIZE__)
#include <inline/dos.h>
#include <inline/exec.h>
#include <inline/gadtools.h>
#include <inline/intuition.h>
#else
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/intuition_protos.h>
#endif
#endif
#include "PointerEyes.Images"
#define DEFAULTXOFFSET 520
int OldPriority, CurCoOrd, CurrentImage, SameImage, PrevCoOrd;
UWORD YOffset=0,XOffset=DEFAULTXOFFSET;
struct Window *EyesWindow;
struct RastPort *Rast;
UBYTE ver[]="\0$VER: PointerEyes 1.1 (7/12/94) John Hughes johughes@heartland.bradley.edu\0";
/*****StartNotify vars/functions********************************************/
struct NotifyRequest *notifyrequest;
LONG reqnotifysignum=NULL;
ULONG startnotsigflag,sigrcvd;
BOOL CreateReqNotify(UBYTE *printerfilespath);
void RemoveReqNotify(void);
/*****Misc prototypes********************************************************/
int GetImageNumber(void);
void ShowImage(void);
void BlinkEyes(void);
void LookAround(void);
void CloseEyes(void);
void GoToSleep(void);
void ShowRequester(STRPTR RequesterText);
/***************************************************************************/
main ()
{
struct Screen *scr;
struct DrawInfo *dr_info;
struct ExecBase *ExecBase;
BOOL LOOP,watch,ToggleLockStat=FALSE;
APTR *EyesVisualInfo;
struct Menu *EyesMenu;
struct NewMenu EyesNewMenu[]={
NM_TITLE, "Project", 0, 0, 0, 0,
NM_ITEM, "Window Locked", "L", CHECKIT|MENUTOGGLE|CHECKED, 0, 0,
IM_ITEM, &RD, "A", 0, 0, 0,
NM_ITEM, "Quit", "Q", 0, 0, 0,
NM_END, NULL, 0, 0, 0, 0 };
UWORD menuNum,itemNum;
struct MenuItem *menuitemaddress;
struct IntuiMessage *MyMessage;
UWORD UseDragBar=0;
BOOL IsFirstTimeThrough=TRUE;
BPTR filehandle;
PrevCoOrd = 0;
srand(time(NULL));
if(ExecBase=(struct ExecBase *)OpenLibrary("exec.library",37))
{
CloseLibrary((struct Library *) ExecBase);
/* Lets watch the prefs drawer */
CreateReqNotify("env:sys");
LOOP=TRUE;
while (LOOP) /** This is the main loop **/
{
/***************************************************/
/* Get the Y location of where to place the window */
/***************************************************/
if (UseDragBar || IsFirstTimeThrough)
{
if (scr=LockPubScreen(NULL))
{
if (dr_info=GetScreenDrawInfo(scr))
{
YOffset=(dr_info->dri_Font->tf_YSize+2-8)/2;
FreeScreenDrawInfo(scr,dr_info);
}
UnlockPubScreen(NULL,scr);
}
}
IsFirstTimeThrough=FALSE;
if (( EyesWindow = OpenWindowTags( NULL,
WA_Left, XOffset,
WA_Top, YOffset,
WA_Width, 40,
WA_Height, 8,
WA_IDCMP, IDCMP_MENUPICK,
WA_Flags, UseDragBar | WFLG_BORDERLESS | WFLG_NEWLOOKMENUS,
WA_Title, "",
TAG_DONE )))
{
/* Set up menus */
if (EyesVisualInfo=GetVisualInfo(EyesWindow->WScreen,TAG_DONE))
{
if (EyesMenu = CreateMenus( EyesNewMenu, GTMN_FrontPen, 0L, TAG_DONE ))
{
if (UseDragBar) /* If the window is unlcoked then Remove the check mark on the Lock menu item */
EyesMenu->FirstItem->Flags ^= CHECKED;
if (LayoutMenus( EyesMenu, EyesVisualInfo, TAG_DONE ))
{
if (SetMenuStrip( EyesWindow, EyesMenu ))
{
GT_RefreshWindow( EyesWindow, NULL ); /* This line may not be needed */
/* Get rasterport to draw images */
Rast=EyesWindow->RPort;
/* Set the task priority lower */
OldPriority = SetTaskPri(FindTask(NULL),-2);
watch=TRUE;
while (watch)
{
/* If the window is not behind all other windows, and it is locked, then Send it to the Back! */
if ((!UseDragBar) && (EyesWindow->WLayer->back->Window!=0)) /*Send the window to the back if we are in locked mode */
WindowToBack(EyesWindow);
sigrcvd = SetSignal(0L,0L);
/* Preferences were modified! */
if (sigrcvd & startnotsigflag)
{
watch=FALSE;
SetSignal(0L,startnotsigflag);
}
/* Quit if CTRL-C was recieved */
if (sigrcvd & SIGBREAKF_CTRL_C)
{
watch=FALSE;
LOOP=FALSE;
}
/* Process IDCMP events */
while (MyMessage = GT_GetIMsg(EyesWindow->UserPort))
{
switch(MyMessage->Class)
{
case IDCMP_MENUPICK:
while( MyMessage->Code != MENUNULL ) {
menuitemaddress = ItemAddress( EyesMenu, MyMessage->Code );
menuNum=MENUNUM(MyMessage->Code);
itemNum=ITEMNUM(MyMessage->Code);
if (menuNum==0)
switch(itemNum)
{
case 0: /* Un/Locked */
/* If the 'Lock Window' menu checkmark has been changed then change the drag bar flag. */
/* Pseudo Code: if ((window is locked and there is a check mark)
or (window is unlocked and there isn't a check mark) */
if ( (UseDragBar && (EyesMenu->FirstItem->Flags & CHECKED))
|| ( (!UseDragBar) && (!(EyesMenu->FirstItem->Flags & CHECKED))))
{
ToggleLockStat=TRUE;
watch=FALSE;
if (UseDragBar==0)
{
UseDragBar=WFLG_DRAGBAR;
}
else
{
YOffset=EyesWindow->TopEdge;
UseDragBar=0;
}
XOffset=EyesWindow->LeftEdge;
}
break;
case 1: /* About */
ShowRequester( "Pointer Eyes v1.1 Copyright © 1994 John Hughes.\n"
"All Rights Reserved.\n\n"
"Written By: John Hughes\n"
"Date: July 12,1994\n\n"
"E-Mail: johughes@heartland.bradley.edu\n");
break;
case 2: /* Quit */
watch=FALSE;
LOOP=FALSE;
break;
}
MyMessage->Code = menuitemaddress->NextSelect;
}
break;
}
GT_ReplyIMsg(MyMessage);
}
/* If the window is going to be closed and or reopened set the priority back up */
if (!watch)
SetTaskPri(FindTask(NULL),OldPriority);
CurrentImage = GetImageNumber();
ShowImage();
Delay(3);
if (CurCoOrd == PrevCoOrd)
SameImage++;
else
{
PrevCoOrd = CurCoOrd;
SameImage = 0;
}
if(SameImage == 200)
{
GoToSleep();
SameImage = 0;
}
if ((rand() % 1000)>993)
BlinkEyes();
} /* End of while(watch) */
/* Clear out all of the waiting messages */
do {
if (MyMessage = GT_GetIMsg(EyesWindow->UserPort))
GT_ReplyIMsg(MyMessage);
} while (MyMessage);
ClearMenuStrip( EyesWindow );
}
FreeMenus( EyesMenu );
}
}
FreeVisualInfo(EyesVisualInfo);
}
CloseWindow(EyesWindow);
}
else
{
ShowRequester("Couldn't Open Window.\n");
LOOP=FALSE;
}
if (ToggleLockStat)
ToggleLockStat=FALSE;
else if (LOOP)
Delay(100); /* Allow preferences time to close/open screen if need be */
}
/* Stop watching the prefs drawer */
RemoveReqNotify();
}
else
{
filehandle=Open("CON:0/10/300/40/Pointer Eyes",MODE_NEWFILE);
Write(filehandle,"You must be running AmigaDOS 2.04 or higher.\n",45);
Delay(50*5);
Close(filehandle);
return(5);
}
}
/*****************************************************************/
int GetImageNumber(void)
{
WORD X, Y;
float Angle;
X = (EyesWindow->MouseX)-20; /* bring it to... (40 div 2 = 20) */
Y = (EyesWindow->MouseY)-4; /* ...the center of the window. (8 div 2 = 4) */
if (X==0) /* We don't want to divide by 0! */
X=1;
Angle=atan((double)(Y/X));/* get Anglele in radians */
Angle=(Angle*180/3.14); /* convert it to degrees */
if (Y==0) /* Check X-axis, since if Y=0, then Y/X=0 and always atan(0)=0 degrees */
Angle=(X>0) ? 0 : 180;
if ((X>0) && (Y>0)) /* Second quadrant */ // IV | I
Angle=360-Angle; // |
else if ((X<0) && (Y>0)) /* Third quadrant */ // ---+---
Angle=abs(Angle)+180; // |
else if ((X<0) && (Y<0)) /* Fourth quadrant */ // III| II
Angle=180-Angle;
else if ((X>0) && (Y<0)) /* First quadrant */
Angle=abs(Angle);
/* now we'll decide which image to show */
CurCoOrd = X + Y;
if ((abs(X)<10) && (abs(Y)<4)) /* Cross Eyed */
return(0);
if ((Angle>=22) && (Angle<68)) /* Upper Right */
return(1);
if ((Angle>=68) && (Angle<112)) /* Up */
return(3);
if ((Angle>=112) && (Angle<158)) /* Upper Left */
return(2);
if ((Angle>=158) && (Angle<202)) /* Left */
return(4);
if ((Angle>=202) && (Angle<247)) /* Lower Left */
return(5);
if ((Angle>=247) && (Angle<292)) /* Down */
return(6);
if ((Angle>=292) && (Angle<338)) /* Lower Right */
return(7);
if ((Angle>=338) || (Angle<22)) /* Right */
return(8);
return(8);
}
void ShowImage(void)
{
/* Place the image of the eyes in the window */
switch(CurrentImage)
{
case 0: DrawImage(Rast,&Crossed, 0, 0); break;
case 1: DrawImage(Rast,&RU, 0, 0); break;
case 2: DrawImage(Rast,&LU, 0, 0); break;
case 3: DrawImage(Rast,&Up, 0, 0); break;
case 4: DrawImage(Rast,&Left, 0, 0); break;
case 5: DrawImage(Rast,&LD, 0, 0); break;
case 6: DrawImage(Rast,&Down, 0, 0); break;
case 7: DrawImage(Rast,&RD, 0, 0); break;
case 8: DrawImage(Rast,&Right, 0, 0); break;
}
}
void BlinkEyes(void)
{
DrawImage(Rast,&NoEyes, 0, 0);
Delay(1);
DrawImage(Rast,&TopBlink, 0, 0);
Delay(1);
DrawImage(Rast,&MidBlink, 0, 0);
Delay(1);
DrawImage(Rast,&BotBlink, 0, 0);
Delay(1);
DrawImage(Rast,&NoEyes, 0, 0);
Delay(12);
DrawImage(Rast,&BotBlink, 0, 0);
Delay(1);
DrawImage(Rast,&MidBlink, 0, 0);
Delay(1);
DrawImage(Rast,&TopBlink, 0, 0);
Delay(1);
DrawImage(Rast,&NoEyes, 0, 0);
Delay(3);
}
void LookAround(void)
{
/* Make the eyes look right then left. */
int count;
for (count=0; count<2; count++)
{
DrawImage(Rast,&Straight, 0, 0);
Delay(3);
DrawImage(Rast,&Right, 0, 0);
Delay(30);
DrawImage(Rast,&Straight, 0, 0);
Delay(6);
DrawImage(Rast,&Left, 0, 0);
Delay(30);
DrawImage(Rast,&Straight, 0, 0);
Delay(3);
}
}
void CloseEyes(void)
{
/* Make eyes shut */
DrawImage(Rast,&NoEyes, 0, 0);
Delay(2);
DrawImage(Rast,&TopBlink, 0, 0);
Delay(2);
DrawImage(Rast,&MidBlink, 0, 0);
Delay(2);
DrawImage(Rast,&BotBlink, 0, 0);
Delay(10);
}
void GoToSleep(void)
{
SameImage = 0;
LookAround();
Delay(10);
CloseEyes();
CurrentImage = GetImageNumber();
while (CurCoOrd == PrevCoOrd)
{
Delay(10);
CurrentImage = GetImageNumber();
SameImage++;
if (SameImage == 150)
{
LookAround();
SameImage = 0;
ShowImage();
Delay(25);
CloseEyes();
}
}
DrawImage(Rast,&MidBlink, 0, 0);
Delay(2);
DrawImage(Rast,&TopBlink, 0, 0);
Delay(2);
DrawImage(Rast,&NoEyes, 0, 0);
Delay(2);
}
BOOL CreateReqNotify(UBYTE *FileOrDir)
{
/* Create a notification for a file or directory */
/* Returns TRUE if successful */
BOOL success=FALSE;
RemoveReqNotify();
if (notifyrequest=AllocMem(sizeof(struct NotifyRequest),MEMF_CLEAR))
{
if ((reqnotifysignum=AllocSignal(-1L))!=-1)
{
startnotsigflag=1L<<reqnotifysignum;
notifyrequest->nr_Name=FileOrDir;
notifyrequest->nr_Flags=NRF_SEND_SIGNAL;
notifyrequest->nr_stuff.nr_Signal.nr_Task=(struct Task *) FindTask(NULL);
notifyrequest->nr_stuff.nr_Signal.nr_SignalNum=reqnotifysignum;
if ((StartNotify(notifyrequest))==DOSTRUE)
success=TRUE;
else
{
ShowRequester("Can't start notification.\n");
FreeSignal(reqnotifysignum);
}
}
else
{
/* No signals available */
FreeMem(notifyrequest,sizeof(struct NotifyRequest));
}
}
else
ShowRequester("Not enough memory for NotifyRequest.\n");
return(success);
}
void RemoveReqNotify(void)
{
/* Removes a notification, if one was created */
if (reqnotifysignum)
{
EndNotify(notifyrequest);
FreeSignal(reqnotifysignum);
reqnotifysignum=NULL;
FreeMem(notifyrequest,sizeof(struct NotifyRequest));
}
}
void ShowRequester(STRPTR RequesterText)
{
struct EasyStruct myRequestStruct={
sizeof (struct EasyStruct ),
0,
"Pointer Eyes",
NULL,
"Ok"};
myRequestStruct.es_TextFormat=RequesterText;
EasyRequestArgs(EyesWindow,&myRequestStruct,NULL,NULL);
}